package demo.day11

import java.util.Objects

// Kotlin 语言的vararg 关键字（动态参数）
fun main() {
    val p:KtBaseDay11_02<Any?> = KtBaseDay11_02("Kiki", 123, "457", 'm', false, null)
    println(p.showObj(0))
    println(p.mapObj(5) {
        it
        it.toString()
        it.toString().length
    })
}


class KtBaseDay11_02<T>(vararg objects: T, var isMap: Boolean = true) {
    // out T只能被读取 不能被修改
    val objArray: Array<out T> = objects
    fun showObj(index: Int) = objArray[index].takeIf { isMap }

    fun <P> mapObj(index: Int, mapAction: (T?) -> P) = mapAction(objArray[index].takeIf { isMap })
}